Markdown files

Jupyter Book allows you to write your content directly in markdown files. If you’d like to include computational content with these markdown files, use the following directive:

```{execute}
print("Here is some code to execute")
```

When your book is build, the contents of any {execute} blocks will be executed with your default Jupyter kernel, and their outputs will be displayed in-line with the rest of your content.

For more information about executing computational content with Jupyter Book, see The MyST-NB documentation.

import numpy as np                     # Load the library

a = np.linspace(-np.pi, np.pi, 100)    # Create even grid from -π to π
b = np.cos(a)                          # Apply cosine to each element of a
c = np.sin(a)                          # Apply sin to each element of a
c
array([-1.22464680e-16, -6.34239197e-02, -1.26592454e-01, -1.89251244e-01,
       -2.51147987e-01, -3.12033446e-01, -3.71662456e-01, -4.29794912e-01,
       -4.86196736e-01, -5.40640817e-01, -5.92907929e-01, -6.42787610e-01,
       -6.90079011e-01, -7.34591709e-01, -7.76146464e-01, -8.14575952e-01,
       -8.49725430e-01, -8.81453363e-01, -9.09631995e-01, -9.34147860e-01,
       -9.54902241e-01, -9.71811568e-01, -9.84807753e-01, -9.93838464e-01,
       -9.98867339e-01, -9.99874128e-01, -9.96854776e-01, -9.89821442e-01,
       -9.78802446e-01, -9.63842159e-01, -9.45000819e-01, -9.22354294e-01,
       -8.95993774e-01, -8.66025404e-01, -8.32569855e-01, -7.95761841e-01,
       -7.55749574e-01, -7.12694171e-01, -6.66769001e-01, -6.18158986e-01,
       -5.67059864e-01, -5.13677392e-01, -4.58226522e-01, -4.00930535e-01,
       -3.42020143e-01, -2.81732557e-01, -2.20310533e-01, -1.58001396e-01,
       -9.50560433e-02, -3.17279335e-02,  3.17279335e-02,  9.50560433e-02,
        1.58001396e-01,  2.20310533e-01,  2.81732557e-01,  3.42020143e-01,
        4.00930535e-01,  4.58226522e-01,  5.13677392e-01,  5.67059864e-01,
        6.18158986e-01,  6.66769001e-01,  7.12694171e-01,  7.55749574e-01,
        7.95761841e-01,  8.32569855e-01,  8.66025404e-01,  8.95993774e-01,
        9.22354294e-01,  9.45000819e-01,  9.63842159e-01,  9.78802446e-01,
        9.89821442e-01,  9.96854776e-01,  9.99874128e-01,  9.98867339e-01,
        9.93838464e-01,  9.84807753e-01,  9.71811568e-01,  9.54902241e-01,
        9.34147860e-01,  9.09631995e-01,  8.81453363e-01,  8.49725430e-01,
        8.14575952e-01,  7.76146464e-01,  7.34591709e-01,  6.90079011e-01,
        6.42787610e-01,  5.92907929e-01,  5.40640817e-01,  4.86196736e-01,
        4.29794912e-01,  3.71662456e-01,  3.12033446e-01,  2.51147987e-01,
        1.89251244e-01,  1.26592454e-01,  6.34239197e-02,  1.22464680e-16])
from ipywidgets import interactive
import matplotlib.pyplot as plt
import numpy as np

def f(m, b):
    plt.figure(2)
    x = np.linspace(-10, 10, num=1000)
    plt.plot(x, m * x + b)
    plt.ylim(-5, 5)
    plt.show()

interactive_plot = interactive(f, m=(-2.0, 2.0), b=(-3, 3, 0.5))
output = interactive_plot.children[-1]
output.layout.height = '350px'
interactive_plot
_images/markdown_2_0.png
import plotly.graph_objects as go
import numpy as np

# Create figure
fig = go.Figure()

# Add traces, one for each slider step
for step in np.arange(0, 5, 0.1):
    fig.add_trace(
        go.Scatter(
            visible=False,
            line=dict(color="#00CED1", width=6),
            name="𝜈 = " + str(step),
            x=np.arange(0, 10, 0.01),
            y=np.sin(step * np.arange(0, 10, 0.01))))

# Make 10th trace visible
fig.data[10].visible = True

# Create and add slider
steps = []
for i in range(len(fig.data)):
    step = dict(
        method="update",
        args=[{"visible": [False] * len(fig.data)},
              {"title": "Slider switched to step: " + str(i)}],  # layout attribute
    )
    step["args"][0]["visible"][i] = True  # Toggle i'th trace to "visible"
    steps.append(step)

sliders = [dict(
    active=10,
    currentvalue={"prefix": "Frequency: "},
    pad={"t": 50},
    steps=steps
)]

fig.update_layout(
    sliders=sliders
)

fig.show()